/*
 * Copyright (c) Zhongkehonglue Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Implementation of functions related to the DMC module.
 * Author: wangchunyang
 * Create: 2025-05-23
 */

#ifndef DMC_PARSE_XML_H
#define DMC_PARSE_XML_H

#include <string>
#include <vector>
#include <memory>
#include "upnp.h"
#include "upnpapi.h"

#include "dmcApiTypes.h"

namespace DlnaDmc {

#define MEDIA_RENDERER_GEN_DEVICE_TYPE "urn:schemas-upnp-org:device:MediaRenderer"

enum DmcServiceType {
    DMC_SERVICE_INVALID = -1,
    DMC_SERVICE_CDS,
    DMC_SERVICE_CMS,
    DMC_SERVICE_AVT,
    DMC_SERVICE_RCS,
    DMC_SERVICE_SRS,
    DMC_SERVICE_XCRCS,
    DMC_SERVICE_EXT
};

struct DmcServiceInfo {
    std::string serviceId;
    std::string serviceType;
    std::string controlUrl;
    std::string eventURL;
    std::string  acSid;
    dmc_int32 subscriptionTimeOut;
    DmcServiceType servType;

    std::vector<std::string> actionVec;
    std::vector<std::string> stateVarVec;
};

// struct DeviceInfo {
//     dmc_uint32 deviceId;
//     std::string friendlyName;
//     std::string udn;
//     std::string deviceType;
//     std::string manufacturer;
//     std::string modelName;

//     std::vector<DmcServiceInfo> serviceVec;
//     dmc_int32 iDeviceMaxAge;
//     dmc_int32 heartBeatFailCnt;
// } ;

struct DevDescInfo {
    std::string descUrl;
    std::string baseUrl;

    dmc_uint32 deviceId;
    std::string friendlyName;
    std::string udn;
    std::string deviceType;
    std::string manufacturer;
    std::string modelName;
    dmc_int64 lastUpdateTime;

    std::vector<DmcServiceInfo> serviceVec;
    dmc_int32 iDeviceMaxAge;
    dmc_int32 heartBeatFailCnt;
};

using DevDescInfoSptr = std::shared_ptr<DevDescInfo>;

bool DmcIsDmrDevice(const char* deviceType);
const char* DmcGetXmlElementValue(IXML_Element *parent, const char *tagName);
const char* DmcGetXmlElementValueFromDoc(IXML_Document *parent, const char *tagName);
const char* DmcParsebaseURL(IXML_Document* p_DevDescripeDoc);
DmcServiceType DmcGetServiceEnumType(char* serviceId);
dmc_int32 DmcGetServiceIdAndType(IXML_Element* serviceEle, DmcServiceInfo &serviceInfo);
 dmc_int32 DmcGetControlUrlAndEventSubUrl(IXML_Element* serviceEle, const std::string &baseURL,
     DmcServiceInfo &serviceInfo);
dmc_int32 DmcParseServiceActions(IXML_Document* serviceDescripeDoc, std::vector<std::string> &actionVec);
dmc_int32 DmcParseStateVars(IXML_Document* serviceDescripeDoc, std::vector<std::string> &stateVarVec);
dmc_int32 DmcParseServiceXml(const char* scpdurl, DmcServiceInfo &serviceInfo);
dmc_int32 DmcGetScpdInfo(IXML_Element* serviceEle, const std::string &baseURL, DmcServiceInfo &serviceInfo);
dmc_int32 DmcGetDevBaseInfo(IXML_Element* deviceElement, DevDescInfo &descInfo);
dmc_int32 DmcParseServiceList(IXML_NodeList* serviceList, DevDescInfo &descInfo);
dmc_int32 DmcGetServiceInfo(IXML_Element* deviceElement, DevDescInfo &descInfo);
dmc_int32 DmcParseDescriptionXml(IXML_Document* devDescripeDoc, UpnpDiscovery* discovery, DevDescInfo &descInfo);
std::shared_ptr<DevDescInfo> DmcGetDescriptionInfo(const void *event);
}
#endif /* DMC_PARSE_XML_H */

